import { defineComponent, ref } from 'vue';
import { useRouter, useRoute } from 'vue-router'
import { useStore } from 'vuex'

export default defineComponent({
  name: 'base',
  components: {},
  setup() {
    const store = useStore()
    const router = useRouter()
    const route = useRoute()
    // const userImg = ref(JSON.parse(localStorage.getItem('userInfo')).avatar)
    const userImg = ref('')
    const userName = '' //导航栏显示用户名称
    //获取userName
    const exit = () => {
      localStorage.clear();
      router.push("/Login");
    }
    const toControlUser = () => {
      router.push("/controlUser")
    }
    const toControlHome = () => {
      router.push("/controlHome")
    }
    const toControlBlog = () => {
      router.push("/controlBlog")
    }
    const controlPermission = () => {
      router.push("/controlPermission")
    }
    const toControlRole = () => {
      router.push("./ControlRole")
    }

    const handlerExitClick = ()  => {
      // 确认退出，调用退出方法
      exit()
    }
    return {
      route,
      store,
      toControlRole,
      exit,
      toControlUser,
      toControlHome,
      toControlBlog,
      userName,
      userImg,
      controlPermission,
      handlerExitClick
    }
  },
  created() {
    if (localStorage.getItem('userInfo')) {
      this.userImg = '/file/' + JSON.parse(localStorage.getItem('userInfo')).avatar
      this.userName = JSON.parse(localStorage.getItem('userInfo')).uName
    }
  },

});
